<template>
  <div>
    <van-card
      v-for="item in list"
      :key="item.id"
      :title="item.title"
      :thumb="item.author.avatar_url"
    >
      <template #footer>
        <p>{{ item.create_at | filtime }}</p>
      </template>
    </van-card>
  </div>
</template>
<script>
export default {
  props: ["list"],
  filters: {
    filtime(val) {
      let num = new Date(val);
      let d = new Date();
      let n = d.getTime();
      let s = n - num;
      var str = "";
      if (s >= 0 && s < 1000 * 60 * 30) {
        str = "30分钟";
      } else if (s >= 1000 * 60 * 30 && s < 1000 * 60 * 60) {
        str = "1小时前";
      } else if (s >= 1000 * 60 * 60 && s < 1000 * 60 * 60 * 24) {
        str = "一天前";
      } else if (s >= 1000 * 60 * 60 * 24 && s < 1000 * 60 * 60 * 24 * 7) {
        str = "7天前";
      } else {
        str = "一个月前";
      }
      return str;
    },
  },
};
</script>